using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Curchy.PERTToolbox.Entity;
using Curchy.PERTToolbox.Service;

namespace Curchy.PERTToolbox.WinUI
{
    public partial class EstimationResult : Form
    {
        private Estimation _est;

        public EstimationResult(Estimation est)
        {
            _est = est;

            InitializeComponent();
        }

        private void EstimationResult_Load(object sender, EventArgs e)
        {
            menuStrip1.Visible = false;
            estimationBindingSource.Add(_est);
            estimationBindingSource.MoveLast();
            lblResult.Text = PresentationFactory.Instance.GeneratePresentation(_est);
        }

        private void txtOpt_TextChanged(object sender, EventArgs e)
        {
            ((TextBoxBase)sender).SuspendLayout();
            ((TextBoxBase)sender).Text = PresentationFactory.FormatLabel(TimeSpan.Parse(((TextBoxBase)sender).Text));
            ((TextBoxBase)sender).ResumeLayout();
        }

        private void txtPro_TextChanged(object sender, EventArgs e)
        {
            ((TextBoxBase)sender).SuspendLayout();
            ((TextBoxBase)sender).Text = PresentationFactory.FormatLabel(TimeSpan.Parse(((TextBoxBase)sender).Text));
            ((TextBoxBase)sender).ResumeLayout();
        }

        private void txtPes_TextChanged(object sender, EventArgs e)
        {
            ((TextBoxBase)sender).SuspendLayout();
            ((TextBoxBase)sender).Text = PresentationFactory.FormatLabel(TimeSpan.Parse(((TextBoxBase)sender).Text));
            ((TextBoxBase)sender).ResumeLayout();
        }

        private void lblResult_Click(object sender, EventArgs e)
        {
             PresentationFactory.Instance.CopyToClipboard(CalendarFactory.Instance.GetSystemSettings(), PresentationFactory.Instance.GenerateFormattedSummary(CalendarFactory.Instance.GetSystemSettings(), _est));
        }

        private void copyEstimateInHTMLToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SystemSettings ss = new SystemSettings();
            ss.Output = "HTML";
            PresentationFactory.Instance.CopyToClipboard(ss, PresentationFactory.Instance.GenerateFormattedSummary(ss, _est));
        }

        private void copyEstimateInTextToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SystemSettings ss = new SystemSettings();
            ss.Output = "Text";
            PresentationFactory.Instance.CopyToClipboard(ss, PresentationFactory.Instance.GenerateFormattedSummary(ss, _est));
        }

        private void generatePDFToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SystemSettings ss = new SystemSettings();
            ss.Output = "HTML"; 
            string pdf = PresentationFactory.Instance.GeneratePDF(PresentationFactory.Instance.GenerateFormattedSummary(ss, _est));
            System.Diagnostics.Process.Start(pdf);
        }

    }
}